Interop Forms Toolkit
How To Raise an Application-Level Event

Overview

It is often required that components be made aware of events that occur which affect an application as a whole.  Examples include notification that an application is starting up or shutting down, or that an unrecoverable error has occurred. For this reason, the InteropToolbox provides an EventMessenger object that allows you to send or receive notification of application-level events. 

 

The following .NET code demonstrates raising an application-level event.  The InteropToolbox can be accessed from the My namespace.

    Private Sub lnkError_LinkClicked(ByVal sender As System.Object, _
        ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkError.LinkClicked
        
        MsgBox("This will simulate a critical error occurring." & vbNewLine & _
            "An event will be raised to notify Visual Basic 6.0 that the application should shut down.", _
            MsgBoxStyle.OkCancel, "Critical Error Event")
        My.InteropToolbox.EventMessenger.RaiseApplicationEvent("CRITICAL_ERROR", _
            "Sample Error Code.")
    End Sub